package ema.tpjee.banking.session;

import java.io.Serializable;
import java.util.List;

import ema.tpjee.banking.controler.BankControler;
import ema.tpjee.banking.controler.CustomerControler;
import ema.tpjee.ejb.banking.entity.Bank;
import ema.tpjee.ejb.banking.entity.Customer;


public class Session implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4885962577769819842L;

	private BankControler bankControler;
	private CustomerControler customerControler;

	private Customer currentCustomer;
	private Bank currentBank;

	public Session() {
		super();
		System.out.println("creating Session");
		/*
		 * if (bankControler.getBankDao().getList().size()==0){ List<Bank> bks =
		 * bankControler.getBankDao().populate(); setCurrentBank(bks.get(0));
		 * List<Customer> csts=
		 * customerControler.getCustomerDao().populateAndTest(getCurrentBank());
		 * setCurrentCustomer(csts.get(0)); }
		 */

	}

	public BankControler getBankControler() {
		System.out.println("getting BankControler");
		if (bankControler.getBankDao().getList().size() == 0) {
			List<Bank> bks= bankControler.getBankDao().populate();///= bankControler.getBankDao().populate();
			setCurrentBank(bks.get(0));
			bankControler.getBankDao().populateAndTest(getCurrentBank());
			List<Customer> csts = customerControler.getCustomerDao().getList(getCurrentBank());
			setCurrentCustomer(csts.get(0));
		}
		return bankControler;
	}

	public void setBankControler(BankControler bankControler) {
		System.out.println("setting BankControler");
		this.bankControler = bankControler;
		bankControler.setSession(this);
	}

	public CustomerControler getCustomerControler() {
		System.out.println("getting CustomerControler");
		return customerControler;
	}

	public void setCustomerControler(CustomerControler customerControler) {
		System.out.println("setting CustomerControler");
		this.customerControler = customerControler;
		customerControler.setSession(this);
	}

	public void setCurrentBank(Bank b) {
		currentBank = b;
	}

	public Bank getCurrentBank() {
		return currentBank;
	}

	public void setCurrentCustomer(Customer c) {
		if (c != null)
			System.out.println("Session.setCurrentCustomer: " + c.toString());
		else
			System.out.println("Session.setCurrentCustomer: null");
		this.currentCustomer = c;
	}

	public Customer getCurrentCustomer() {

		return currentCustomer;
	}

}
